from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.support.ui import Select
from time import sleep
from options import options
from service import service

dr=webdriver.Chrome(options=options,service=service)
url=r'http://172.16.22.105:8080/bsams/front/login.do'
dr.get(url)
dr.maximize_window()
sleep(3)

# 资产管理
# 点击资产管理
dr.find_element(By.LINK_TEXT,'资产管理').click()
# 下拉框选择使用
ele=dr.find_element(By.ID,'status')
Select(ele).select_by_index(1)
sleep(1)
# 文本框输入内容查询
dr.find_element(By.ID,'title').clear()
dr.find_element(By.ID,'title').send_keys('华为华硕')
sleep(1)
# 点击搜索图标
dr.find_element(By.CLASS_NAME,'search_button').click()
sleep(1)
# 点击新增
dr.find_element(By.CLASS_NAME,'button_true').click()
sleep(1)
# 资产名称输入
dr.find_element(By.XPATH,'//*[@id="title"]').clear()
dr.find_element(By.XPATH,'//*[@id="title"]').send_keys('今日热点')
sleep(1)
# 存放地点下拉框选择辽宁异界公司
ele=dr.find_element(By.ID,'providerId')
Select(ele).select_by_index(4)
sleep(1)
# 存放地点下拉框选择电脑设备库
ele1=dr.find_element(By.ID,'storageId')
Select(ele1).select_by_index(1)
sleep(1)
# 点击确定按钮
dr.find_element(By.XPATH,'//*[@id="fm_new"]/div/div[1]/div/div[1]').click()
sleep(1)
# 处理警告弹窗
# 获取本文
text=dr.switch_to.alert.text
print(text)
sleep(3)
# 点击确定
dr.switch_to.alert.accept()
sleep(3)
# 修改
dr.find_element(By.LINK_TEXT,'休改').click()
sleep(1)
# 资产名称输入
dr.find_element(By.XPATH,'//*[@id="title"]').clear()
dr.find_element(By.XPATH,'//*[@id="title"]').send_keys('明日热点')
sleep(1)
# 存放地点下拉框选择电脑设备库
ele2=dr.find_element(By.ID,'storageId')
Select(ele2).select_by_index(1)
sleep(1)
# 供应商下拉框选择深圳华克科技公司
ele3=dr.find_element(By.ID,'providerId')
Select(ele3).select_by_index(1)
sleep(1)
# 点击确定按钮
dr.find_element(By.XPATH,'//*[@id="fm_new"]/div/div[1]').click()
sleep(1)
# 处理警告弹窗
# 获取本文
text=dr.switch_to.alert.text
print(text)
sleep(3)
# 点击确定
dr.switch_to.alert.accept()
sleep(3)

# 选择第一条数据 借用
dr.find_elements(By.LINK_TEXT,'借用')[0].click()
sleep(1)
# 借用部分下拉框选择软件部
ele4=dr.find_element(By.ID,'departId')
Select(ele4).select_by_index(2)
sleep(1)
# 备注说明
dr.find_element(By.ID,'remark').clear()
dr.find_element(By.ID,'remark').send_keys('这是一个说明')
sleep(3)
# 点击确定按钮
dr.find_element(By.XPATH,'//*[@id="fm_new"]/div/div[1]').click()
sleep(3)
# 处理警告弹窗
# 获取本文
text=dr.switch_to.alert.text
print(text)
sleep(3)
# 点击确定
dr.switch_to.alert.accept()
sleep(3)
# 归还
dr.find_elements(By.LINK_TEXT,'归还')[0].click()
sleep(1)
# 点击确定
dr.find_element(By.XPATH,'//*[@id="cboxLoadedContent"]/div/div/div[2]/div[2]/div[1]').click()
sleep(1)
# 处理警告弹窗
# 获取本文
text=dr.switch_to.alert.text
print(text)
sleep(3)
# 点击确定
dr.switch_to.alert.accept()
sleep(3)
# 退出
dr.find_element(By.LINK_TEXT,'退出').click()
sleep(1)
dr.quit()